﻿using System.Collections.Generic;
using WikiPlex;
using WikiPlex.Compilation.Macros;
using WikiPlex.Parsing;
using Xunit;

namespace WikiMaml.Facts.Augmenters
{
    public class TableScopeAugmenterFacts
    {
        public class Augment
        {
            [Fact]
            public void Should_add_the_table_header_scopes()
            {
                var origScopes = new List<Scope>(new[]
                        {
                            new Scope(ScopeName.TableRowHeaderBegin, 0, 1),
                            new Scope(ScopeName.TableCellHeader, 1, 1),
                            new Scope(ScopeName.TableRowHeaderEnd, 2, 1)
                        });

                var augmenter = new WikiMaml.Augmenters.TableScopeAugmenter();

                IList<Scope> actualScopes = augmenter.Augment(new TableMacro(), origScopes, null);

                Assert.Equal(7, actualScopes.Count);
                Assert.Equal(MamlScopeName.TableHeaderBegin, actualScopes[1].Name);
                Assert.Equal(0, actualScopes[1].Index);
                Assert.Equal(1, actualScopes[1].Length);
                Assert.Equal(MamlScopeName.TableHeaderEnd, actualScopes[5].Name);
                Assert.Equal(3, actualScopes[5].Index);
                Assert.Equal(0, actualScopes[5].Length);
            }

            [Fact]
            public void Should_add_the_table_header_scopes_with_table_cells()
            {
                var origScopes = new List<Scope>(new[]
                        {
                            new Scope(ScopeName.TableRowHeaderBegin, 0, 1),
                            new Scope(ScopeName.TableCellHeader, 1, 1),
                            new Scope(ScopeName.TableRowHeaderEnd, 2, 1),
                            new Scope(ScopeName.TableRowBegin, 4, 1),
                            new Scope(ScopeName.TableCell, 5, 1),
                            new Scope(ScopeName.TableRowEnd, 6, 1)
                        });

                var augmenter = new WikiMaml.Augmenters.TableScopeAugmenter();

                IList<Scope> actualScopes = augmenter.Augment(new TableMacro(), origScopes, null);

                Assert.Equal(10, actualScopes.Count);
                Assert.Equal(MamlScopeName.TableHeaderBegin, actualScopes[1].Name);
                Assert.Equal(0, actualScopes[1].Index);
                Assert.Equal(1, actualScopes[1].Length);
                Assert.Equal(MamlScopeName.TableHeaderEnd, actualScopes[5].Name);
                Assert.Equal(3, actualScopes[5].Index);
                Assert.Equal(0, actualScopes[5].Length);
            }
        }
    }
}
